package com.enqualcomm.kids.mvp.chat;

import java.util.ArrayList;

/**
 * Created by yinzhiqun on 2015/5/30.
 * 处理观察者相关的逻辑
 */
public abstract class AbstractPlayerManager implements IPlayerManager{
    private ArrayList<PlayerObserver> observers = new ArrayList<>();

    @Override
    public void addObserver(PlayerObserver o){
        observers.add(o);
    }

    @Override
    public void removeObserver(PlayerObserver o){
        observers.remove(o);
    }

    protected void notifyObservers(int status){
        for (PlayerObserver o : observers){
            o.update(status,this);
        }
    }

    /**
     * 释放资源,在activity销毁时调用
     */
    protected abstract void localRelease();

    @Override
    public void release() {
        observers.clear();

        localRelease();
    }
}
